package com.pro.control;

import com.pro.entity.*;
import com.pro.service.UserListService;
import com.pro.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.xml.ws.spi.http.HttpContext;
import java.lang.reflect.Array;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @author ：刘弘禹
 * @description：TODO
 * @date ：2021/11/15 13:48
 */
@Controller
@RequestMapping("/UserList")
public class UserListController {
    @Autowired
    private UserListService userListService;

    @RequestMapping("/queryBeforeUser")
    @ResponseBody
    public JsonData queryBeforeUser(BeforeUser beforeUser){
        List<BeforeUser> beforeUsers = userListService.queryBeforeUser(beforeUser);
        return beforeUsers != null ? JsonData.buildSuccess(beforeUsers):JsonData.buildError("服务器错误");
    }

    @RequestMapping("/updateStudyDate")
    @ResponseBody
    public JsonData updateStudyDate(Integer study,Integer id){
        Boolean aBoolean = userListService.updateStudyDate(study, id);
        return aBoolean != null ? JsonData.buildSuccess(aBoolean):JsonData.buildError("服务器错误");
    }

    @RequestMapping("/addClosure")
    @ResponseBody
    public JsonData addClosure(Closure closure){
        Boolean aBoolean = userListService.addClosure(closure);
        return aBoolean != null ? JsonData.buildSuccess(aBoolean):JsonData.buildError("服务器错误");
    }

    @RequestMapping("/updateBeforeUser")
    @ResponseBody
    public JsonData updateBeforeUser(BeforeUser beforeUser){
        Boolean aBoolean = userListService.updateBeforeUser(beforeUser);
        return aBoolean != null ? JsonData.buildSuccess(aBoolean):JsonData.buildError("服务器错误");
    }

    @RequestMapping("/addBeforeUser")
    @ResponseBody
    public JsonData addBeforeUser(BeforeUserPlus beforeUserPlus){
        Boolean beforeUserPlus1 = userListService.addBeforeUser(beforeUserPlus);
        return beforeUserPlus1 != null ? JsonData.buildSuccess(beforeUserPlus1):JsonData.buildError("服务器错误");
    }

    @RequestMapping("/queryCoupons")
    @ResponseBody
    public JsonData queryCoupons() {
        List<UserCoupon> coupons = userListService.queryCoupons();
        return coupons!=null? JsonData.buildSuccess(coupons):JsonData.buildError("服务器错误");
    }

    @RequestMapping("/addUserCouponUsed")
    @ResponseBody
    public JsonData addUserCouponUsed(Integer couponId,Integer[] obj) {
        Boolean aBoolean = userListService.addUserCouponUsed(couponId,obj);
        return aBoolean != null ? JsonData.buildSuccess(aBoolean):JsonData.buildError("服务器错误");
    }

    @RequestMapping("/queryJinSiBeforeUser")
    @ResponseBody
    public JsonData queryJinSiBeforeUser(BeforeUserPlus beforeUser) {
        List<CourseOrderPlus> beforeUsers = userListService.queryJinSiBeforeUser(beforeUser);
        return beforeUsers != null ? JsonData.buildSuccess(beforeUsers):JsonData.buildError("服务器错误");
    }

    @RequestMapping("/queryWrongJinSiBeforeUser")
    @ResponseBody
    public JsonData queryWrongJinSiBeforeUser(BeforeUserPlus beforeUser) {
        List<BeforeUser> beforeUsers = userListService.queryWrongJinSiBeforeUser(beforeUser);
        return beforeUsers != null ? JsonData.buildSuccess(beforeUsers):JsonData.buildError("服务器错误");
    }

    //查询前台封停账号
    @RequestMapping("/queryUserLockoutList")
    @ResponseBody
    public JsonData queryUserLockoutList(ClosurePlus closurePlus) {
        closurePlus.setType(2);
        List<ClosurePlus> closurePluses = userListService.queryUserLockoutList(closurePlus);
        return closurePluses != null ? JsonData.buildSuccess(closurePluses):JsonData.buildError("服务器错误");
    }


    @RequestMapping("/unseal")
    @ResponseBody
    public JsonData unseal(Integer id,Integer userId,Integer createdId) {
        Boolean unseal = userListService.unseal(id, userId,createdId);
        return unseal != null ? JsonData.buildSuccess(unseal):JsonData.buildError("服务器错误");
    }

    @RequestMapping("/queryUnseal")
    @ResponseBody
    public JsonData queryUnseal(UnsealPlus unsealPlus) {
        List<UnsealPlus> unsealPluses = userListService.queryUnseal(unsealPlus);
        return unsealPluses != null ? JsonData.buildSuccess(unsealPluses):JsonData.buildError("服务器错误");
    }

    @RequestMapping("/delUnseal")
    @ResponseBody
    public JsonData delUnseal(Integer id) {
        Boolean aBoolean = userListService.delUnseal(id);
        return aBoolean != null ? JsonData.buildSuccess(aBoolean):JsonData.buildError("服务器错误");
    }

}
